import collections
class Solution(object):
    def mostFrequent(self, nums, key):
        d = collections.defaultdict(int)
        n = len(nums)
        for i in range(n - 1):
            if nums[i] == key:
                d[nums[i + 1]] += 1
        v = max(d.values())
        for k in d:
            if d[k] == v:
                return k

data = Solution()
nums = [1,100,200,1,100]
key = 1
print(data.mostFrequent(nums, key))

